/**
 * 
 */
package com.yst.metho.web.application.team.actions;

import nextapp.echo2.app.Button;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.event.ActionEvent;
import nextapp.echo2.app.event.ActionListener;
import nextapp.echo2.app.event.ChangeEvent;
import nextapp.echo2.app.event.ChangeListener;
import nextapp.echo2.app.list.ListSelectionModel;

import com.yst.metho.web.application.team.TeamRoleListModel;
import com.yst.suivi.data.team.TeamDto;
import com.yst.suivi.data.team.TeamRoleDto;

/**
 * @author yannick
 * 
 */
public class DeleteRole extends Button implements ActionListener, ChangeListener
{
	private TeamDto mTeamDto;

	private TeamRoleDto mSelectedTeam;

	private TeamRoleListModel mModel;

	public DeleteRole(TeamDto teamDto, TeamRoleListModel model)
	{
		super("Delete");
		addActionListener(this);
		setWidth(new Extent(30, Extent.PX));
		mTeamDto = teamDto;
		mModel = model;
	}

	public void actionPerformed(ActionEvent arg0)
	{
		mTeamDto.remove(mSelectedTeam);
		mModel.fireTableDataChanged();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.yst.metho.web.application.components.listingview.ToolbarAction#stateChanged(nextapp.echo2.app.event.ChangeEvent)
	 */
	public void stateChanged(ChangeEvent arg0)
	{
		ListSelectionModel model = (ListSelectionModel) arg0.getSource();
		setEnabled(!model.isSelectionEmpty());
		if (!model.isSelectionEmpty())
		{
			int selectedIndex = model.getMinSelectedIndex();
			mSelectedTeam = (TeamRoleDto) mModel.getValueAt(0, selectedIndex);
		}
	}
}
